package com.zwr.sheller.shop.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.WQQBusinessException;
import com.zwr.sheller.core.pojo.Sign;
import com.zwr.sheller.shop.service.SignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: 18032
 * @Date: 11:19 2022/1/6
 */
@RestController
@RequestMapping("/sign")
@CrossOrigin
@Api(tags = "/店招管理")
public class SignController {

    @Autowired(required = false)
    SignService signService;

    @PostMapping("/selectAllSigns")
    @ApiOperation("店招管理,点击全查询店招信息")
    public Map<String,Object> selectAllSigns(){
        List<Sign> sign = signService.selectAllSigns();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("data",sign);
        return jsonResult.getMap();
    }

    @PostMapping("/addSign")
    @ApiOperation("店招管理,点击添加店招")
    @ApiImplicitParam(name = "sign",value = "sign对象",dataType = "Sign")
    public Map<String,Object> addSign(Sign sign) throws WQQBusinessException {
        System.out.println(sign+"_____sign");
        Integer integer = signService.insertSign(sign);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("msg","添加成功");
        return jsonResult.getMap();
    }

    @PostMapping("/updateSign")
    @ApiOperation("店招管理,点击编辑店招")
    @ApiImplicitParam(name = "sign" ,value = "店招id",dataType = "Sign")
    public Map<String,Object> updateSign(Sign sign) throws WQQBusinessException {
        Integer integer = signService.updateSign(sign);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("msg","修改成功");
        return jsonResult.getMap();
    }

    @PostMapping("/deleteSign")
    @ApiOperation("店招管理,点击删除店招")
    @ApiImplicitParam(name = "signId" ,value = "店招id",dataType = "Long")
    public Map<String,Object> deleteSign(Long signId) throws WQQBusinessException {
        Integer integer = signService.deleteSign(signId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setField("msg","删除成功");
        return jsonResult.getMap();
    }
}
